# 作者：石吴震
# 2024年12月30日10时25分07秒
# 474160957@qq.com


class HouseItem:
    def __init__(self, name, aera):
        self.name = name
        self.aera = aera

    def __str__(self):
        return f"[{self.name}]占地{self.aera}平方米"


class House:
    def __init__(self, home_type, aera):
        self.home_type = home_type
        self.aera = aera
        self.free_area = aera
        self.items_list = []

    def __str__(self):
        items_str = ", ".join(str(item) for item in self.items_list)  # 列表转字符串,用逗号分隔,join()方法
        return (f"房子类型：{self.home_type}\n"
                f"房子面积：{self.aera}平方米\n"
                f"空闲面积：{self.free_area}平方米\n"
                f"家具：{items_str}")

    def add_item(self, item: HouseItem):
        if item.aera > self.free_area:
            print("家具占地面积超过房子空闲面积，无法添加")
            return
        else:
            self.items_list.append(item)
            self.free_area -= item.aera


if __name__ == '__main__':
    ximengsi=HouseItem('席梦思',20)
    print(ximengsi)
    chest=HouseItem('衣柜',10)
    print(chest)
    table=HouseItem('桌子',5)
    xiaofangzi=House('小房子',40)
    xiaofangzi.add_item(ximengsi)

    xiaofangzi.add_item(chest)

    xiaofangzi.add_item(table)
    print(xiaofangzi)
